/**
 * @api {get} /api/admin/v1/user_orders/analyse 订单统计
 * @apiGroup AdminOrders
 * @apiDescription 订单管理-订单统计
 * @apiPermission 管理员(查看订单权限)
 * @apiVersion 1.0.0
 */
exports.analyse = function ({}, {models: {UserOrders}}) {
    return UserOrders.analyseV2();
}

/**
 * @api {get} /api/admin/v1/user_orders/browse 订单列表
 * @apiGroup AdminOrders
 * @apiDescription 订单管理-订单列表
 * @apiPermission 管理员(查看订单权限)
 * @apiVersion 1.0.0
 */
exports.browse = function ({query}, {models: {UserOrders, Users, associations}, controller}) {
    let pagination = controller.pagination({
        params: query,
        filters: ['taobaoTradeParentId', 'user_id', 'status'],
        likes: ['taobaoTradeParentId', 'user_id']
    });
    return UserOrders.findAndCountAll(pagination).then(function (data) {
        return associations.relateOne(data, Users, 'user_id', 'user', ['id', 'image', 'username', 'nickname', 'tel', 'order_count', 'finish_count', 'sham_count', 'amount', 'frozen']);
    });
}
